package thread.pool;

import java.util.concurrent.*;

/**
 * @program: Multhread
 * @description:
 * @author: zhanghz001
 * @create: 2021-03-04 15:40
 **/
public class MyExecutorService extends ThreadPoolExecutor {
    public MyExecutorService(int corePoolSize, int maximumPoolSize, long keepAliveTime,
                             TimeUnit unit, BlockingQueue<Runnable> workQueue,
                             RejectedExecutionHandler handler) {
        super(corePoolSize, maximumPoolSize, keepAliveTime, unit, workQueue, handler);
    }
    
    @Override
    protected void terminated() {
        super.terminated();
        System.out.println("terminated");
    }
    
    public static void main(String[] args) {
        MyExecutorService service = new MyExecutorService(1, 1,
                1, TimeUnit.MILLISECONDS
                , new LinkedBlockingQueue<Runnable>()
                , new ThreadPoolExecutor.AbortPolicy());
        service.execute(() ->
        
        {
            try {
                Thread.sleep(1000);
                System.out.println("finish task 1");
            } catch (Exception e) {
                e.printStackTrace();
            } finally {
                
            }
        });
        service.shutdown();
        service.execute(() ->
        {
            try {
                Thread.sleep(1000);
                System.out.println("finish task 2");
            } catch (Exception e) {
                e.printStackTrace();
            } finally {
                
            }
        });
        System.out.println("ok");
    }
}
